package handler

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"litter-api/app/service"
	"litter-api/app/util"
)

type Login struct {
	service *service.UserService
}

//Login
/**
 *author:Leedong
 *notes:授权
 *date:12:11 上午 2022/8/2
 **/
func (l *Login) Login(ctx *gin.Context) {
	openId := ctx.PostForm("open_id")

	fmt.Println(openId)
	count := l.service.Login(openId)
	if count == 0 {
		util.Failed(ctx, "查无此号用户!")
		return
	}
	jwt := util.Jwt{}
	token, err := jwt.GenerateToken(openId)
	if err != nil {
		util.Failed(ctx, "授权失败!")
		return
	}
	util.Success(ctx, token)

}
